package com.simon.hse.activity.safe.jobticket.commonly;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.simon.hse.MyApplication;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.adapter.CommonEmptyAdapter;
import com.simon.hse.adapter.CommonViewHolder;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 一般吊装作业审批查询
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_commomly_query_list)
public class CommonlyApprovalQueryListActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.iv_common_right)
    ImageView mIv_common_right;

    @ViewInject(R.id.tv_function_1)
    TextView mTv_function_1;
    @ViewInject(R.id.ll_function_1)
    LinearLayout mLl_function_1;

    @ViewInject(R.id.tv_function_2)
    TextView mTv_function_2;
    @ViewInject(R.id.ll_function_2)
    LinearLayout mLl_function_2;

    @ViewInject(R.id.tv_function_3)
    TextView mTv_function_3;
    @ViewInject(R.id.ll_function_3)
    LinearLayout mLl_function_3;

    @ViewInject(R.id.common_swiperefreshlayout)
    SwipeRefreshLayout mSwipeRefreshLayout;

    @ViewInject(R.id.common_recyclerview)
    RecyclerView mRecyclerView;

    private int currentPage = 1, totalPage = 1;
    private CommonEmptyAdapter mCommonEmptyAdapter;
    private List<String> mDataBeanList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("一般吊装作业许可证审批");
        mIv_common_right.setImageResource(R.mipmap.tab_add_icon);

        initRecyclerView();
        initData();
    }

    @Event(value = {R.id.iv_common_left, R.id.iv_common_right, R.id.ll_function_1, R.id.ll_function_2, R.id.ll_function_3})
    private void clickButton(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.iv_common_right:
                Intent intent = new Intent(CommonlyApprovalQueryListActivity.this, CommonlyApplyActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_function_1:
                initSafePop(mLl_function_1, mTv_function_1, MyApplication.getInstance().mSafeWorkUnitList);
                break;
            case R.id.ll_function_2:
                publishSafeDate(mTv_function_2);
                break;
            case R.id.ll_function_3:
                publishSafeDate(mTv_function_3);
                break;
        }
    }

    private void initRecyclerView() {
        LinearLayoutManager llm = new LinearLayoutManager(CommonlyApprovalQueryListActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);
        mCommonEmptyAdapter = new CommonEmptyAdapter(CommonlyApprovalQueryListActivity.this, R.layout.layout_item_commonly_query, mDataBeanList);
        mCommonEmptyAdapter.setItemDatasListener(new CommonEmptyAdapter.ItemDatasListener<String>() {
            @Override
            public void setItemDatas(CommonViewHolder holder, String dataBean, int position) {
                TextView tv_state = holder.getView(R.id.tv_safe_work_state);
                tv_state.setText("待审批");
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                startActivity(new Intent(CommonlyApprovalQueryListActivity.this, CommonlyDetailsActivity.class).putExtra("from", "approval"));
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
    }

    private void initData() {
        mTv_function_1.setHint("作业单位");
        mTv_function_2.setHint("申请时间");
        mTv_function_3.setHint("起止时间");


        for (int i = 0; i < 7; i++) {
            mDataBeanList.add(i + "");
        }
        mCommonEmptyAdapter.notifyDataSetChanged();
    }
}
